import request from '../utils/request';

// 开票管理相关API
export const invoiceApi = {
  // 根据验收单ID查询开票单列表
  getInvoicesByAcceptanceId: (acceptanceId) => {
    return request.get(`/api/invoice/acceptance/${acceptanceId}`);
  },

  // 根据项目ID查询开票单列表
  getInvoicesByProjectId: (projectId) => {
    return request.get(`/api/invoice/project/${projectId}`);
  },

  // 根据开票状态查询开票单列表
  getInvoicesByInvoiceStatus: (invoiceStatus) => {
    return request.get(`/api/invoice/status/${invoiceStatus}`);
  },

  // 根据ID查询开票单详情
  getInvoiceById: (id) => {
    return request.get(`/api/invoice/${id}`);
  },

  // 创建开票单
  createInvoice: (data) => {
    return request.post('/api/invoice', data);
  },

  // 更新开票单
  updateInvoice: (id, data) => {
    return request.put(`/api/invoice/${id}`, data);
  },

  // 更新开票状态
  updateInvoiceStatus: (id, invoiceStatus) => {
    return request.put(`/api/invoice/${id}/status`, null, {
      params: { invoiceStatus }
    });
  },

  // 计算项目总开票金额
  calculateTotalInvoiceAmount: (projectId) => {
    return request.get(`/api/invoice/project/${projectId}/total-amount`);
  },

  // 根据验收单自动创建开票单
  createInvoiceFromAcceptance: (acceptanceId) => {
    return request.post(`/api/invoice/from-acceptance/${acceptanceId}`);
  },

  // 删除开票单
  deleteInvoice: (id) => {
    return request.delete(`/api/invoice/${id}`);
  }
};

